﻿namespace GraphEntities
    
open System
open System.Collections
open System.Collections.Generic
open NumericalFunctions
    ///// {=========================Point=========================}
    type Point =
        ///-----------------------------Fields-----------------------------
        val mutable m_x:double
        val mutable m_y:double

        ///-----------------------------Constructors-----------------------------
        new(x,y) = 
            {m_x = x ; m_y = y}

        new(point:double[]) = 
            if point.Length <> 2 then
                raise (Exception("Cannot create Point(double[]): input massive error"))
            {m_x = point.[0] ; m_y = point.[1]}

        ///-----------------------------Properties-----------------------------
        member this.X with get()  = this.m_x
                       and set(x) = this.m_x <- x
        member this.Y with get()  = this.m_y
                       and set(y) = this.m_y <- y
        member this.AsDoubleMass () = [|this.m_x ; this.m_y|]

        ///-----------------------------Operators-----------------------------
        ///-----------------------------Methods-----------------------------
        ///-----------------------------InterfaceImplementation------------------

    ///// {=========================Points=========================}
    type Points = 
        ///-----------------------------Fields-----------------------------
        val mutable m_points:System.Collections.Generic.List<Point>

        ///-----------------------------Constructors-----------------------------
        public new() = 
            {
                m_points = new System.Collections.Generic.List<Point>()
            }

        public new(pointsArray:double[][]) = 
            let pointsDoubleArray = 
                pointsArray |>
                Array.map (fun doubleCouple ->
                                if doubleCouple.Length <> 2 then
                                    raise (Exception("Points new(double[][]): double massive format error"))
                                new Point(doubleCouple.[0],doubleCouple.[1]))
            {
                m_points = new List<Point>(pointsDoubleArray)
            }
        public new(pointsList:System.Collections.Generic.List<Point>) = 
            {
                m_points = pointsList
            }

        ///-----------------------------Properties-----------------------------
        member this.PointList   
            with get() = new List<Point>(this.m_points)
            and set(points:List<Point>) = 
                    this.m_points <- points

        member this.Count
            with get() = this.m_points.Count

        member this.AsPointSeq() = 
            seq{
                for point:Point in this.m_points do
                    yield point
            }

        member this.AsMassOfDoubleMass() = 
            this.m_points.ToArray() |>
            Array.map (fun point ->
                point.AsDoubleMass())
                                                    
        member this.GetXValues  () = 
            this.m_points.ToArray() |>
            Array.map (fun point -> point.X)

        member this.GetYValues  () = 
            this.m_points.ToArray() |>
            Array.map (fun point ->point.Y)

        ///-----------------------------Operators-----------------------------
        member this.Item
            with get(idx:int) = 
                this.m_points.[idx]

        ///-----------------------------Methods-----------------------------
        member x.Add (point:Point) = 
            x.m_points.Add(point)
            
        ///-----------------------------InterfaceImplementation------------------
        interface IEnumerable with
            member this.GetEnumerator() = this.m_points.ToArray().GetEnumerator()
        member x.GetEnumerator() = (x:>IEnumerable).GetEnumerator()


        










